package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.Order;
import com.ymatou.iapi.trading.operate.parameter.OrderInfoPo;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.req.ApplySalesRefundRequestBean;
import com.ymatou.iapi.trading.operate.parameter.req.SalesRefundInfoBean;
import com.ymatou.iapi.trading.operate.service.ApplySalesRefundRequestCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.model.YmtRefundBill;
import com.ymttest.database.model.YmtRefundProduct;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtRefundWapper;
import com.ymttest.utils.DataUtil;

/**
 * 申请退货退款接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_ApplySalesRefundRequest {
	private static ApplySalesRefundRequestBean applysalesrefundrequestBean;
	private static ApplySalesRefundRequestCall applysalesrefundrequestCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("申请退货退款接口");
	}

	@Before
	public void caseUp() {

		applysalesrefundrequestBean = new ApplySalesRefundRequestBean();
		applysalesrefundrequestCall = new ApplySalesRefundRequestCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(applysalesrefundrequestCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	//商品申请退款的上限值为：当个商品最大可退款金额+订单总运费

	// 计算订单总价格 商品价格 X 数量+运费
	/*	BigDecimal refoundAmout = orderInfoPo.getProductPrice()
				.multiply(new BigDecimal(productNum))
				.subtract(orderInfoPo.getYmtCouponAmount())
				.subtract(orderInfoPo.getSellerCouponAmount());

		//单件商品可退金额

		BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
				productNum), 2, BigDecimal.ROUND_DOWN);*/

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_001() {

		Logger.start(true, "申请退货退款成功");
		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = placeOrderResp.getPayAmount();
			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			applysalesrefundrequestBean.setOrderId(orderId);

			// 订单商品明细

			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			for (int i = 0; i < orderInfoList.size(); i++) {

				OrderInfoPo orderInfoPo = orderInfoList.get(i);

				String catalogId = orderInfoPo.getCatalogId();
				String productId = orderInfoPo.getProductId();

				int productNum = orderInfoPo.getAmount();

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = (orderInfoPo.getProductPrice())
						.multiply(new BigDecimal(productNum))
						.subtract(orderInfoPo.getSellerCouponAmount())
						.subtract(orderInfoPo.getYmtCouponAmount());
				SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();
				salesRefundInfo.setCatalogId(catalogId);
				// productid 丢在resaon 里，校验数据用
				salesRefundInfo.setReason(productId);
				salesRefundInfo.setRefundAmount(refoundAmout);
				salesRefundInfo.setRefundBillNo("TH" + i + orderId);
				salesRefundInfo.setRefundProductNum(orderInfoPo.getAmount());
				salesRefundInfo.setRefundType(1);

				salesRefundInfoList.add(salesRefundInfo);
			}
			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");
			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				/*				int isFrozen = new DefaultWapper().getFrozenStatus(orderId);

								Logger.verifyEquals(1, isFrozen, "验证Ymt_Order_Frozen.bFrozen");;*/

				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {
					String refundBillNo = refund.getRefundBillNo();

					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);

					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(0);

					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(0);
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getRefundAmount(), "验证RefundAmount");
					Logger.verifyEquals(0, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getSettlementAmount(),
							"验证SettlementAmount");
					Logger.verifyEquals(1, refundBill.getSalesRefundStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(refund.getRefundType(),
							refundBill.getRefundType(), "验证RefundType");
					Logger.verifyEquals(refund.getReason(),
							refundBill.getReason(), "验证Reason");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");

					DataUtil.verifyDecimalEquals(BigDecimal.ZERO,
							refundBill.getRefundedAmountOfFreight(),
							"验证RefundedAmountOfFreight");

					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getReason(),
							refundPro.getProductId(), "验证ProductId");
					Logger.verifyEquals(refund.getCatalogId(),
							refundPro.getCatalogId(), "验证CatalogId");
					Logger.verifyEquals(refund.getRefundProductNum(),
							refundPro.getRefundProductNum(),
							"验证RefundProductNum");

				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_002() {
		Logger.start(false, "申请退货退款,订单号不存在");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			applysalesrefundrequestBean.setOrderId(11111);
			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();
			SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();
			salesRefundInfo.setCatalogId("ssss");
			salesRefundInfo.setReason("autotest");
			salesRefundInfo.setRefundAmount(new BigDecimal(100));
			salesRefundInfo.setRefundBillNo("YMTTF" + orderId);
			salesRefundInfo.setRefundProductNum(1);
			salesRefundInfo.setRefundType(1);
			salesRefundInfoList.add(salesRefundInfo);
			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_003() {
		Logger.start(true, "发货后,申请退货退款成功");
		try {

			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			applysalesrefundrequestBean.setOrderId(orderId);

			OrderCallService orderCallService = new OrderCallService();
			// 应付款全金额
			BigDecimal amount = orderCallService
					.getNeedPrePayAmountOfCash(orderId);
			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			// 订单商品明细
			List<Map> ymtOrdersInfoList = new DefaultWapper()
					.selectOrderInfoByOderId(orderId);
			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();
			BigDecimal totalPrice = new BigDecimal(0);
			for (int i = 0; i < ymtOrdersInfoList.size(); i++) {
				String catalogId = (String) ymtOrdersInfoList.get(i).get(
						"sCatalogId");
				String productId = (String) ymtOrdersInfoList.get(i).get(
						"sProductId");
				// 如果規格為null,給個默認值
				int productNum = (Integer) ymtOrdersInfoList.get(i).get(
						"iAmount");
				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = ((BigDecimal) ymtOrdersInfoList
						.get(i).get("fProductPrice")).multiply(new BigDecimal(
						productNum));
				SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();
				salesRefundInfo.setCatalogId(catalogId);
				// productid 丢在resaon 里，校验数据用
				salesRefundInfo.setReason(productId);
				salesRefundInfo.setRefundAmount(refoundAmout);
				salesRefundInfo.setRefundBillNo("TH" + i + orderId);
				salesRefundInfo.setRefundProductNum(productNum);
				salesRefundInfo.setRefundType(1);
				salesRefundInfoList.add(salesRefundInfo);
			}
			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");
			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {
					String refundBillNo = refund.getRefundBillNo();
					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(0);
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(0);
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getRefundAmount(), "验证RefundAmount");
					Logger.verifyEquals(0, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getSettlementAmount(),
							"验证SettlementAmount");
					Logger.verifyEquals(1, refundBill.getSalesRefundStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(refund.getRefundType(),
							refundBill.getRefundType(), "验证RefundType");
					Logger.verifyEquals(refund.getReason(),
							refundBill.getReason(), "验证Reason");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getReason(),
							refundPro.getProductId(), "验证ProductId");
					Logger.verifyEquals(refund.getCatalogId(),
							refundPro.getCatalogId(), "验证CatalogId");
					Logger.verifyEquals(refund.getRefundProductNum(),
							refundPro.getRefundProductNum(),
							"验证RefundProductNum");
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_004() {
		Logger.start(true, "发货后,部分退款");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			applysalesrefundrequestBean.setOrderId(orderId);
			OrderCallService orderCallService = new OrderCallService();
			// 应付款全金额
			BigDecimal amount = orderCallService
					.getNeedPrePayAmountOfCash(orderId);
			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			// 订单商品明细
			List<Map> ymtOrdersInfoList = new DefaultWapper()
					.selectOrderInfoByOderId(orderId);
			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			String catalogId = (String) ymtOrdersInfoList.get(0).get(
					"sCatalogId");
			String productId = (String) ymtOrdersInfoList.get(0).get(
					"sProductId");
			// 如果規格為null,給個默認值
			int productNum = (Integer) ymtOrdersInfoList.get(0).get("iAmount");

			BigDecimal refoundAmout = new BigDecimal(13);
			SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();
			salesRefundInfo.setCatalogId(catalogId);

			// productid 丢在resaon 里，校验数据用
			salesRefundInfo.setReason(productId);
			salesRefundInfo.setRefundAmount(refoundAmout);
			salesRefundInfo.setRefundBillNo("TH" + 0 + orderId);
			salesRefundInfo.setRefundProductNum(productNum);
			salesRefundInfo.setRefundType(1);
			salesRefundInfoList.add(salesRefundInfo);

			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");
			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {
					String refundBillNo = refund.getRefundBillNo();
					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(0);
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(0);
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getRefundAmount().setScale(2),
							refundBill.getRefundAmount(), "验证RefundAmount");
					Logger.verifyEquals(0, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(refund.getRefundAmount().setScale(2),
							refundBill.getSettlementAmount(),
							"验证SettlementAmount");
					Logger.verifyEquals(1, refundBill.getSalesRefundStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(refund.getRefundType(),
							refundBill.getRefundType(), "验证RefundType");
					Logger.verifyEquals(refund.getReason(),
							refundBill.getReason(), "验证Reason");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getReason(),
							refundPro.getProductId(), "验证ProductId");
					Logger.verifyEquals(refund.getCatalogId(),
							refundPro.getCatalogId(), "验证CatalogId");
					Logger.verifyEquals(refund.getRefundProductNum(),
							refundPro.getRefundProductNum(),
							"验证RefundProductNum");
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_005() {
		Logger.start(true, "同一退款单，重复申请退款");
		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = orderCallService
					.getNeedPrePayAmountOfCash(orderId);
			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			applysalesrefundrequestBean.setOrderId(orderId);
			// 订单商品明细
			List<Map> ymtOrdersInfoList = new DefaultWapper()
					.selectOrderInfoByOderId(orderId);
			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();
			BigDecimal totalPrice = new BigDecimal(0);
			for (int i = 0; i < ymtOrdersInfoList.size(); i++) {
				String catalogId = (String) ymtOrdersInfoList.get(i).get(
						"sCatalogId");
				String productId = (String) ymtOrdersInfoList.get(i).get(
						"sProductId");
				// 如果規格為null,給個默認值
				int productNum = (Integer) ymtOrdersInfoList.get(i).get(
						"iAmount");
				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = ((BigDecimal) ymtOrdersInfoList
						.get(i).get("fProductPrice")).multiply(new BigDecimal(
						productNum));
				SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();
				salesRefundInfo.setCatalogId(catalogId);
				// productid 丢在resaon 里，校验数据用
				salesRefundInfo.setReason(productId);
				salesRefundInfo.setRefundAmount(refoundAmout);
				salesRefundInfo.setRefundBillNo("TH" + i + orderId);
				salesRefundInfo.setRefundProductNum(productNum);
				salesRefundInfo.setRefundType(1);
				salesRefundInfoList.add(salesRefundInfo);
			}
			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_006() {

		Logger.start(true, "订单商品不是包邮,商品申请全额退款，退商品及商品运费");

		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			BigDecimal totalOrderInfoFreight = orderInfoList.stream()
					.map(item -> item.getFreight())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			applysalesrefundrequestBean.setOrderId(orderId);

			// 订单商品明细

			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			for (int i = 0; i < orderInfoList.size(); i++) {

				OrderInfoPo orderInfoPo = orderInfoList.get(i);

				String catalogId = orderInfoPo.getCatalogId();

				String productId = orderInfoPo.getProductId();

				int productNum = orderInfoPo.getAmount();

				BigDecimal productFreight = orderInfoPo.getFreight();

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = orderInfoPo.getProductPrice()
						.multiply(new BigDecimal(productNum))
						.add(productFreight)
						.subtract(orderInfoPo.getSellerCouponAmount())
						.subtract(orderInfoPo.getYmtCouponAmount());

				SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();

				salesRefundInfo.setCatalogId(catalogId);

				// productid 丢在resaon 里，校验数据用
				salesRefundInfo.setReason(productId);
				salesRefundInfo.setRefundAmount(refoundAmout);
				salesRefundInfo.setRefundBillNo("TH" + i + orderId);
				salesRefundInfo.setRefundProductNum(productNum);
				salesRefundInfo.setRefundType(1);

				salesRefundInfoList.add(salesRefundInfo);

			}
			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				int isFrozen = new DefaultWapper().getFrozenStatus(orderId);

				Logger.verifyEquals(1, isFrozen, "验证Ymt_Order_Frozen.bFrozen");;

				int i = 0;

				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {

					String refundBillNo = refund.getRefundBillNo();

					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);

					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(0);

					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(0);
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getRefundAmount(), "验证RefundAmount");
					Logger.verifyEquals(0, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getSettlementAmount(),
							"验证SettlementAmount");
					Logger.verifyEquals(1, refundBill.getSalesRefundStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(refund.getRefundType(),
							refundBill.getRefundType(), "验证RefundType");
					Logger.verifyEquals(refund.getReason(),
							refundBill.getReason(), "验证Reason");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");

					DataUtil.verifyDecimalEquals(orderInfoList.get(i)
							.getFreight(), refundBill
							.getRefundedAmountOfFreight(),
							"验证RefundedAmountOfFreight");

					Logger.comment("校验Ymt_RefundProduct表");

					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getReason(),
							refundPro.getProductId(), "验证ProductId");
					Logger.verifyEquals(refund.getCatalogId(),
							refundPro.getCatalogId(), "验证CatalogId");
					Logger.verifyEquals(refund.getRefundProductNum(),
							refundPro.getRefundProductNum(),
							"验证RefundProductNum");

					i++;

				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_007() {

		Logger.start(true, "商品申请退款金额大于(商品可退金额+订单总运费)");

		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			BigDecimal totalOrderInfoFreight = order.getFreight();

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			applysalesrefundrequestBean.setOrderId(orderId);

			// 订单商品明细

			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			OrderInfoPo orderInfoPo = orderInfoList.get(0);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.add(totalOrderInfoFreight).add(BigDecimal.ONE);

			SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();

			salesRefundInfo.setCatalogId(catalogId);

			// productid 丢在resaon 里，校验数据用
			salesRefundInfo.setReason(productId);
			salesRefundInfo.setRefundAmount(refoundAmout);
			salesRefundInfo.setRefundBillNo("TH" + 0 + orderId);
			salesRefundInfo.setRefundProductNum(productNum);
			salesRefundInfo.setRefundType(1);

			salesRefundInfoList.add(salesRefundInfo);

			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				int i = 0;

				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {

					String refundBillNo = refund.getRefundBillNo();

					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);

					List<YmtRefundBill> refundBillList = ymtRefund
							.selectRefundBill(m);

					List<YmtRefundProduct> ymtRefundProductList = ymtRefund
							.selectRefundProduct(m);

					Logger.verifyEquals(0, refundBillList.size(),
							"Ymt_RefundBill 记录数为0");

					Logger.verifyEquals(0, ymtRefundProductList.size(),
							"Ymt_RefundProduct 记录数为0");

					i++;

				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_008() {

		Logger.start(true, "订单商品不是包邮,商品申请退款，只退商品，不退运费");

		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			applysalesrefundrequestBean.setOrderId(orderId);

			// 订单商品明细

			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			for (int i = 0; i < orderInfoList.size(); i++) {

				OrderInfoPo orderInfoPo = orderInfoList.get(i);

				String catalogId = orderInfoPo.getCatalogId();

				String productId = orderInfoPo.getProductId();

				int productNum = orderInfoPo.getAmount();

				BigDecimal productFreight = orderInfoPo.getFreight();

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = orderInfoPo.getProductPrice()
						.multiply(new BigDecimal(productNum))
						.subtract(orderInfoPo.getYmtCouponAmount())
						.subtract(orderInfoPo.getSellerCouponAmount());

				SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();

				salesRefundInfo.setCatalogId(catalogId);

				// productid 丢在resaon 里，校验数据用
				salesRefundInfo.setReason(productId);
				salesRefundInfo.setRefundAmount(refoundAmout);
				salesRefundInfo.setRefundBillNo("TH" + i + orderId);
				salesRefundInfo.setRefundProductNum(productNum);
				salesRefundInfo.setRefundType(1);

				salesRefundInfoList.add(salesRefundInfo);

			}
			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				int isFrozen = new DefaultWapper().getFrozenStatus(orderId);

				Logger.verifyEquals(1, isFrozen, "验证Ymt_Order_Frozen.bFrozen");;

				int i = 0;

				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {

					String refundBillNo = refund.getRefundBillNo();

					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);

					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(0);

					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(0);

					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getRefundAmount(), "验证RefundAmount");
					Logger.verifyEquals(0, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getSettlementAmount(),
							"验证SettlementAmount");
					Logger.verifyEquals(1, refundBill.getSalesRefundStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(refund.getRefundType(),
							refundBill.getRefundType(), "验证RefundType");
					Logger.verifyEquals(refund.getReason(),
							refundBill.getReason(), "验证Reason");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");

					DataUtil.verifyDecimalEquals(BigDecimal.ZERO,
							refundBill.getRefundedAmountOfFreight(),
							"验证RefundedAmountOfFreight");

					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getReason(),
							refundPro.getProductId(), "验证ProductId");
					Logger.verifyEquals(refund.getCatalogId(),
							refundPro.getCatalogId(), "验证CatalogId");
					Logger.verifyEquals(refund.getRefundProductNum(),
							refundPro.getRefundProductNum(),
							"验证RefundProductNum");

					i++;

				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_009() {

		Logger.start(true, "订单商品不是包邮,商品申请退款， 商品部分退款");

		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			BigDecimal totalOrderInfoFreight = orderInfoList.stream()
					.map(item -> item.getFreight())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			applysalesrefundrequestBean.setOrderId(orderId);

			// 订单商品明细

			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			for (int i = 0; i < orderInfoList.size(); i++) {

				OrderInfoPo orderInfoPo = orderInfoList.get(i);

				String catalogId = orderInfoPo.getCatalogId();

				String productId = orderInfoPo.getProductId();

				int productNum = orderInfoPo.getAmount();

				BigDecimal productFreight = orderInfoPo.getFreight();

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = orderInfoPo.getProductPrice()
						.multiply(new BigDecimal(productNum))
						.subtract(orderInfoPo.getYmtCouponAmount())
						.subtract(orderInfoPo.getSellerCouponAmount())
						.subtract(new BigDecimal(19));

				SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();

				salesRefundInfo.setCatalogId(catalogId);

				// productid 丢在resaon 里，校验数据用
				salesRefundInfo.setReason(productId);
				salesRefundInfo.setRefundAmount(refoundAmout);
				salesRefundInfo.setRefundBillNo("TH" + i + orderId);
				salesRefundInfo.setRefundProductNum(productNum);
				salesRefundInfo.setRefundType(1);

				salesRefundInfoList.add(salesRefundInfo);

			}
			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				int isFrozen = new DefaultWapper().getFrozenStatus(orderId);

				Logger.verifyEquals(1, isFrozen, "验证Ymt_Order_Frozen.bFrozen");;

				int i = 0;

				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {

					String refundBillNo = refund.getRefundBillNo();

					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);

					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(0);

					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(0);

					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getRefundAmount(), "验证RefundAmount");
					Logger.verifyEquals(0, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getSettlementAmount(),
							"验证SettlementAmount");
					Logger.verifyEquals(1, refundBill.getSalesRefundStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(refund.getRefundType(),
							refundBill.getRefundType(), "验证RefundType");
					Logger.verifyEquals(refund.getReason(),
							refundBill.getReason(), "验证Reason");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");

					DataUtil.verifyDecimalEquals(BigDecimal.ZERO,
							refundBill.getRefundedAmountOfFreight(),
							"验证RefundedAmountOfFreight");

					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getReason(),
							refundPro.getProductId(), "验证ProductId");
					Logger.verifyEquals(refund.getCatalogId(),
							refundPro.getCatalogId(), "验证CatalogId");
					Logger.verifyEquals(refund.getRefundProductNum(),
							refundPro.getRefundProductNum(),
							"验证RefundProductNum");

					i++;

				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_010() {

		Logger.start(true, "订单商品不是包邮,商品申请退款，全品全退，退部分商品运费");

		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			BigDecimal totalOrderInfoFreight = orderInfoList.stream()
					.map(item -> item.getFreight())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			applysalesrefundrequestBean.setOrderId(orderId);

			// 订单商品明细

			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			OrderInfoPo orderInfoPo = orderInfoList.get(0);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(1));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount())
					.add(refundProductFreight);

			SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();

			salesRefundInfo.setCatalogId(catalogId);

			// productid 丢在resaon 里，校验数据用
			salesRefundInfo.setReason(productId);
			salesRefundInfo.setRefundAmount(refoundAmout);
			salesRefundInfo.setRefundBillNo("TH" + 0 + orderId);
			salesRefundInfo.setRefundProductNum(productNum);
			salesRefundInfo.setRefundType(1);

			salesRefundInfoList.add(salesRefundInfo);

			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();
			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				int isFrozen = new DefaultWapper().getFrozenStatus(orderId);

				Logger.verifyEquals(1, isFrozen, "验证Ymt_Order_Frozen.bFrozen");;

				int i = 0;

				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {

					String refundBillNo = refund.getRefundBillNo();

					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);

					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(0);

					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(0);

					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getRefundAmount(), "验证RefundAmount");
					Logger.verifyEquals(0, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getSettlementAmount(),
							"验证SettlementAmount");
					Logger.verifyEquals(1, refundBill.getSalesRefundStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(refund.getRefundType(),
							refundBill.getRefundType(), "验证RefundType");
					Logger.verifyEquals(refund.getReason(),
							refundBill.getReason(), "验证Reason");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");

					DataUtil.verifyDecimalEquals(refundProductFreight,
							refundBill.getRefundedAmountOfFreight(),
							"验证RefundedAmountOfFreight");

					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getReason(),
							refundPro.getProductId(), "验证ProductId");
					Logger.verifyEquals(refund.getCatalogId(),
							refundPro.getCatalogId(), "验证CatalogId");
					Logger.verifyEquals(refund.getRefundProductNum(),
							refundPro.getRefundProductNum(),
							"验证RefundProductNum");

					i++;

				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_011() {

		Logger.start(true, "订单商品不是包邮,同意商品多次申请退款，第一次商品全额退款，商品运费还未退完，第二次申请退部分运费");

		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			applysalesrefundrequestBean.setOrderId(orderId);

			// 订单商品明细

			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			OrderInfoPo orderInfoPo = orderInfoList.get(0);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();

			salesRefundInfo.setCatalogId(catalogId);

			// productid 丢在resaon 里，校验数据用
			salesRefundInfo.setReason(productId);
			salesRefundInfo.setRefundAmount(refoundAmout);
			salesRefundInfo.setRefundBillNo("TH" + 0 + orderId);
			salesRefundInfo.setRefundProductNum(productNum);
			salesRefundInfo.setRefundType(1);

			salesRefundInfoList.add(salesRefundInfo);

			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);

			//商品第一次申请退款
			orderCallService
					.applySalesRefundRequestCall(applysalesrefundrequestBean);

			//商品第二次申请退款

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(refundProductFreight);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundBillNo("TH" + 1 + orderId);

			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				int isFrozen = new DefaultWapper().getFrozenStatus(orderId);

				Logger.verifyEquals(1, isFrozen, "验证Ymt_Order_Frozen.bFrozen");;

				int i = 0;

				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {

					String refundBillNo = refund.getRefundBillNo();

					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);

					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(0);

					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(0);

					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getRefundAmount(), "验证RefundAmount");
					Logger.verifyEquals(0, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(refund.getRefundAmount(),
							refundBill.getSettlementAmount(),
							"验证SettlementAmount");
					Logger.verifyEquals(1, refundBill.getSalesRefundStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(refund.getRefundType(),
							refundBill.getRefundType(), "验证RefundType");
					Logger.verifyEquals(refund.getReason(),
							refundBill.getReason(), "验证Reason");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");

					DataUtil.verifyDecimalEquals(BigDecimal.ZERO,
							refundBill.getRefundedAmountOfFreight(),
							"验证RefundedAmountOfFreight");

					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(refundBillNo,
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(refund.getReason(),
							refundPro.getProductId(), "验证ProductId");
					Logger.verifyEquals(refund.getCatalogId(),
							refundPro.getCatalogId(), "验证CatalogId");
					Logger.verifyEquals(refund.getRefundProductNum(),
							refundPro.getRefundProductNum(),
							"验证RefundProductNum");

					i++;

				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ApplySalesRefundRequest_012() {

		Logger.start(true, "订单里有包邮非包邮混合商品,包邮商品全退+退部分运费");

		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder8();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			//第一个订单下的商品列表
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			OrderCallService orderCallService = new OrderCallService();

			BigDecimal amount = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			applysalesrefundrequestBean.setOrderId(orderId);

			// 订单商品明细

			List<SalesRefundInfoBean> salesRefundInfoList = new ArrayList<SalesRefundInfoBean>();

			OrderInfoPo orderInfoPo = orderInfoList.get(1);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount())
					.add(BigDecimal.TEN);

			SalesRefundInfoBean salesRefundInfo = new SalesRefundInfoBean();

			salesRefundInfo.setCatalogId(catalogId);

			// productid 丢在resaon 里，校验数据用
			salesRefundInfo.setReason(productId);
			salesRefundInfo.setRefundAmount(refoundAmout);
			salesRefundInfo.setRefundBillNo("TH" + 0 + orderId);
			salesRefundInfo.setRefundProductNum(productNum);
			salesRefundInfo.setRefundType(1);

			salesRefundInfoList.add(salesRefundInfo);

			applysalesrefundrequestBean
					.setSalesRefundInfoList(salesRefundInfoList);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(refoundAmout);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundBillNo("TH" + 0 + orderId);

			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

			Logger.verifyEquals("ok",
					applysalesrefundrequestCall.getReturnData(),
					"验证申请退货退款接口返回正常");

			if (applysalesrefundrequestCall.getReturnData().equals("ok")) {
				// 数据库验证
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				for (SalesRefundInfoBean refund : applysalesrefundrequestBean
						.getSalesRefundInfoList()) {

					String refundBillNo = refund.getRefundBillNo();

					Map m = new HashMap();
					m.put("orderId", orderId);
					m.put("refundBillNo", refundBillNo);

					Logger.verifyEquals(0,
							ymtRefund.selectRefundBill(m).size(),
							"验证Ymt_RefundBill 表数据记录");

					Logger.verifyEquals(0, ymtRefund.selectRefundProduct(m)
							.size(), "验证Ymt_RefundProduct 表数据记录");

				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
